﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Web;

namespace NExt.Handler.Base.Default
{
    public class DefaultResponseStreamBuilder: IReponseStreamBuilder
    {
        private readonly IContentBuilder contentBuilder;

        public DefaultResponseStreamBuilder(IContentBuilder contentBuilder)
        {
            this.contentBuilder = contentBuilder;
        }

        public Stream Build(HttpContext context)
        {
            MemoryStream stream = new MemoryStream();
            StreamWriter streamWriter = new StreamWriter(stream);
            String content = contentBuilder.Build(context);
            streamWriter.Write(content);
            streamWriter.Flush();
            return stream;
        }
    }
}
